#!/bin/bash

echo '<background>'
echo '  <starttime>'
echo '    <year>2009</year>'
echo '    <month>08</month>'
echo '    <day>04</day>'
echo '    <hour>00</hour>'
echo '    <minute>00</minute>'
echo '    <second>00</second>'
echo '  </starttime>'
echo '<!-- This animation will start at midnight. -->'

files=`ls -U /usr/share/backgrounds/private | grep -v contest`
last_file='empty'
first_file='empty'
static=1795.0
transition=5.0

for current_file in $files
do
    if [[ $last_file == 'empty' ]]
    then
        last_file=$current_file
        first_file=$current_file
        echo '  <static>'
        echo "    <duration>$static</duration>"
        echo "    <file>/usr/share/backgrounds/private/$last_file</file>"
        echo '  </static>'
    else
        echo '  <transition>'
        echo "    <duration>$transition</duration>"
        echo "    <from>/usr/share/backgrouds/private/$last_file</from>"
        echo "    <to>/usr/share/backgrouds/private/$current_file</to>"
        echo '  </transition>'
        echo '  <static>'
        echo "    <duration>$static</duration>"
        echo "    <file>/usr/share/backgrounds/private/$current_file</file>"
        echo '  </static>'
        last_file=$current_file
    fi
done

echo '  <transition>'
echo "    <duration>$transition</duration>"
echo "    <from>/usr/share/backgrouds/private/$last_file</from>"
echo "    <to>/usr/share/backgrouds/private/$first_file</to>"
echo '  </transition>'
echo '</background>'
